import requests

s = requests.Session()

# 登陆
url = 'http://localhost:8888/smeoa/index.php?m=login&a=check_login'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
datas = {'emp_no': 'admin', 'password': 'admin'}
r = s.post(url, data=datas)
if '退出' in r.text:
    print('登陆成功')
else:
    print('登陆失败')

# 上传文件: 获取sid做为下一个请求的参数
url = 'http://localhost:8888/smeoa/task/upload'
file = {'file': open(r'D:\Python\APITest\demo_Requests\test.txt', 'rb')}
datas = {'name': 'test0228.txt'}
r = s.post(url, files=file, data=datas)
# print(r.json())
sid = r.json()['sid']
print(sid)

# 日报-发布任务
url = 'http://localhost:8888/smeoa/task/save'
datas = {'name': 'title01', 'expected_time': '2019-07-02 14:40', 'content': 'content01', 'opmode': 'add',
         'add_file': sid}
r = s.post(url, data=datas)
if '新增成功' in r.text:
    print('新增成功')
else:
    print('新增失败')
